package com.example.a28796.beautiful.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a28796.beautiful.R;
import com.example.a28796.beautiful.bean.FirstPageBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 28796 on 2016/8/30.
 */
public class FirstPageAdapter extends BaseAdapter{
    private List<FirstPageBean.ObjBean.AreasBean> mData;
    private Context mContext;
    public FirstPageAdapter(List<FirstPageBean.ObjBean.AreasBean> data, Context context) {
        mData = data;
        mContext = context;
        Log.i("gaofengFirstPageAdapter", "FirstPageAdapter: "+mData.size());
    }
    @Override
    public int getCount() {
        return mData==null?0:mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
         ViewHolderOne holder = null;
        if(convertView==null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_fragment_first,null);
            holder = new ViewHolderOne(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolderOne) convertView.getTag();
        }
            final FirstPageBean.ObjBean.AreasBean areasBean = mData.get(position);
            final String areaName = areasBean.getAreaName();
            holder.mTextView1.setText(areaName);
            final List<FirstPageBean.ObjBean.AreasBean.ListItemsBean> listItems =areasBean.getListItems();
            for (int b = 0; b <listItems.size() ; b++) {
                final String title = listItems.get(b).getTitle();
                final String summary = listItems.get(b).getSummary();
                final String url = listItems.get(b).getCover().getUrl();
                Picasso.with(mContext).load(url).into(holder.mImageView);
                holder.mTextView2.setText(title);
                holder.mTextView3.setText(summary);

        }

        return convertView;
    }
    public static class ViewHolderOne{
        private TextView mTextView1,mTextView2,mTextView3;
        private ImageView mImageView;
        public ViewHolderOne(View view){
            mImageView = (ImageView) view.findViewById(R.id.iv_item_first);
            mTextView1 = (TextView) view.findViewById(R.id.tv_item_first1_title);
            mTextView2 = (TextView) view.findViewById(R.id.tv_item_smalltitle);
            mTextView3 = (TextView) view.findViewById(R.id.tv_item_content);
        }
    }
}
